
const cinemasDao = require('../dao/theatersDao.js');

module.exports = {
    //查询
    async findAll({ currentPage, pageSize }) {
        //需要封装的分页对象
        let pageBean = {};
        //封装当前页数
        pageBean.currentPage = currentPage;
        //封装每页显示的条数
        pageBean.pageSize = pageSize;
        //封装显示的数据
        let res = await cinemasDao.queryAllCinemas({ currentPage, pageSize });
        //封装显示的数据
        pageBean.datas = res;
        //封装总条数和总页数
        let nums = await cinemasDao.getTolNums();
        //封装总条数
        pageBean.totalNum = nums;
        //计算出总页数
        pageBean.totalSize = Math.ceil(nums / pageSize);
        return pageBean;
        // return await cinemasDao.queryAllCinemas();
    },
    //id 查询
    async findone(id) {
        return await cinemasDao.queryCinemas(id);
    },
    // 地区查询
    async addressQuery(address) {
        return await cinemasDao.typequery(address);
    },
    //添加
    async addCinema(name, address, phone, status, photo) {
        if (status === '是') {
            return await cinemasDao.addCinema(name, address, phone, !!status, photo);
        } else {

            return await cinemasDao.addCinema(name, address, phone, !status, photo);
        }
    },
    //删除
    async delCinema(id) {
        return await cinemasDao.deleteCinema(id);
    },
    //图片修改
    async editCinema(id, name, address, phone, status, photo) {
        if (status == '是') {
            status = Boolean(1 == 1)
            return await cinemasDao.editCinema(id, name, address, phone, status, photo);
        } else {
            status = Boolean(1 == 2)
            return await cinemasDao.editCinema(id, name, address, phone, status, photo);
        }
    },
    //修改
    async edited(id, name, address, phone, status) {
        if (status == '是') {
            status = Boolean(1 == 1)
            return await cinemasDao.edit(id, name, address, phone, status);
        } else {
            status = Boolean(1 == 2)
            return await cinemasDao.edit(id, name, address, phone, status);
        }
    }
}